'use strict'

 const { DataTypes, Model, Op } = require('../../azeroth').sequelize;
 class JobInfo extends Model { }

  const initJobData = (sequelize_aim) => {
    JobInfo.init(
      {
        uid: {
            field: 'uid',
            type: DataTypes.BIGINT(11) ,
            allowNull: false,
            primaryKey: true,
            autoIncrement: true
        },
        job_name: {
            field: 'job_name',
            type: DataTypes.STRING,
        },
        panel_sum: {
            field: 'panel_sum',
            type: DataTypes.INTEGER
        },
        ok_number: {
            field: 'ok_number',
            type: DataTypes.INTEGER
        },
        ng_number: {
            field: 'ng_number',
            type: DataTypes.INTEGER
        },
        start_time: {
            field: 'start_time',
            type: DataTypes.BIGINT
        },
        finish_time: {
            field: 'finish_time',
            type: DataTypes.BIGINT
        },
        start_time_str: {
            field: 'start_time_str',
            type: DataTypes.STRING
        },
        finish_time_str: {
            field: 'finish_time_str',
            type: DataTypes.STRING
        },
        order_number: {
          field: 'order_number',
          type: DataTypes.STRING
        }
      },
      {
        freezeTableName: true,
        sequelize: sequelize_aim,
        modelName: 'job',
        timestamps: false
      }
     )
  }

  JobInfo.uploadJobInfo = async (data) => {
     let res = await JobInfo.bulkCreate([...data], {updateOnDuplicate: ['uid', 'ok_number', 'ng_number', 'order_number', 'job_name']});
     return res;
 }

 module.exports = {
     JobInfo,
     initJobData
 };